package com.yexin.mail.search.controller;

import com.yexin.common.exception.BizCodeEnum;
import com.yexin.common.to.es.SkuEsModel;
import com.yexin.common.utils.R;
import com.yexin.mail.search.service.ProductSaveService;
import java.io.IOException;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping(value = "/search/save")
public class ElasticSaveController {

    @Autowired
    ProductSaveService productSaveService;

    @PostMapping("/product")
    public R productStatusUp(@RequestBody List<SkuEsModel> skuEsModels) {
        boolean b = false;
        try {
            b = productSaveService.pruductStatusUP(skuEsModels);
        } catch (IOException e) {
            log.error("es error 商品上级错误", e);
            return R.error(BizCodeEnum.PROUDUCT_UP_EXCEPTION.getCode(), BizCodeEnum.PROUDUCT_UP_EXCEPTION.getMsg());
        }
        if (b) {
            return R.ok();
        } else {
            return R.error(BizCodeEnum.PROUDUCT_UP_EXCEPTION.getCode(), BizCodeEnum.PROUDUCT_UP_EXCEPTION.getMsg());
        }


    }
}
